﻿using VideoStore.Domain.Entities;
using VideoStore.Services.Dto;
using VideoStore.Services.Translation.Base;

namespace VideoStore.Services.Translation
{
    public class CustomerTranslator : BaseTranslator
    {
        #region Overrides of BaseTranslator

        /// <summary>
        /// Translates to concrete entity.
        /// </summary>
        /// <typeparam name="TDto">The type of the dto.</typeparam>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <param name="dto">The dto.</param>
        /// <param name="concreteEntity">The concrete entity.</param>
        /// <returns></returns>
        public override TEntity TranslateToConcreteEntity<TDto, TEntity>(TDto dto, TEntity concreteEntity)
        {
            CustomerDto customerDto = dto as CustomerDto;
            if (customerDto != null)
            {
                Customer customerEntity = concreteEntity as Customer;
                if (customerEntity != null)
                {
                    customerEntity.id = customerDto.Id;
                    customerEntity.name = customerDto.Name;
                    customerEntity.address = customerDto.Address;
                    return customerEntity as TEntity;
                }
            }
            return default(TEntity);
        }

        /// <summary>
        /// Translates to concrete dto.
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <typeparam name="TDto">The type of the dto.</typeparam>
        /// <param name="entity">The entity.</param>
        /// <param name="concreteDto">The concrete dto.</param>
        /// <returns></returns>
        public override TDto TranslateToConcreteDto<TEntity, TDto>(TEntity entity, TDto concreteDto)
        {
            Customer customerEntity = entity as Customer;
            if (customerEntity != null)
            {
                CustomerDto customerDto = concreteDto as CustomerDto;
                if (customerDto != null)
                {
                    customerDto.Id = customerEntity.id;
                    customerDto.Name = customerEntity.name;
                    customerDto.Address = customerEntity.address;
                    return customerDto as TDto;
                }
            }
            return default(TDto);
        }

        #endregion
    }
}